JavaScript Regular Expressions by 2015

JavaScript Regular Expressions by 2015
Author: 2015
Language: eng
Format: epub, mobi
Publisher: Packt Publishing
Published: 2015-07-31

All the groups we have seen so far have been capture groups, and they tell Regexp to extract this portion of the pattern into its own variable. However, there are other groups or uses for brackets that can be made to achieve even more functionality, the first of these is a non capture group.

Matching non capture groups

A non capture group groups a part of a pattern but it does not actually extract this data into the results array, or use it in back referencing. One benefit of this is that it allows you to use character modifiers on full sections in your pattern. For example, if we want to get a pattern that repeats world indefinitely, we can write it as this:

/(?:world)*/